package com.mj;

import com.mj.entity.Student;
import com.mj.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class Demo {
    @Test
    public void tt(){
        InputStream im = null;
        try {
            im = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(im);
        SqlSession sqlSession = sf.openSession();
        StudentMapper sm = sqlSession.getMapper(StudentMapper.class);
        Student student = new Student();
        student.setName("王麻子");
        student.setAge(11);
        student.setDept("保安队");
        student.setScore("300");
        sm.insert(student);
        sqlSession.commit();
    }
}
